/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * TokenSource.java
 * wholebasic
 * 2014年4月3日下午4:28:44
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.web.taglib;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.commons.lang3.StringUtils;

public class TokenSource extends SimpleTagSupport {
       private int count=0;
       private String delims=",";
       private String var="tokens";
       
       
	@Override
	public void doTag() throws JspException, IOException {
		Collection<Integer> strs = new ArrayList<>(count);
		for(int i=0;i<count;i++)strs.add(i);	   
	    String str = StringUtils.join(strs, delims);	    
	    this.getJspContext().setAttribute(var, str, PageContext.PAGE_SCOPE);
	   
	}
	public int getCount() {
		return count;
	}
	public String getDelims() {
		return delims;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public void setDelims(String delims) {
		this.delims = delims;
	}
	public String getVar() {
		return var;
	}
	public void setVar(String var) {
		this.var = var;
	}
       
}
